<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
    <title></title>
    <meta name="description" content="overview & stats"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="static/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="static/css/bootstrap-responsive.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="static/css/font-awesome.min.css"/>
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/css/chosen.css"/>
    <link rel="stylesheet" href="static/css/ace.min.css"/>
    <link rel="stylesheet" href="static/css/ace-responsive.min.css"/>
    <link rel="stylesheet" href="static/css/ace-skins.min.css"/>
    <script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
    <!--提示框-->
    <script type="text/javascript" src="static/js/jquery.tips.js"></script>

    <script type="text/javascript">
        $(top.hangge());
        $(document).ready(function () {
            if ($("#user_id").val() != "") {
                $("#loginname").attr("readonly", "readonly");
                $("#loginname").css("color", "gray");
            }
        });

        //保存
        function save() {

            if ($("#app_id").val() == "") {

                $("#app_id").tips({
                    side: 3,
                    msg: '选择应用平台',
                    bg: '#AE81FF',
                    time: 2
                });

                $("#app_id").focus();
                return false;
            }

            if ($("#role_id").val() == "") {

                $("#role_id").tips({
                    side: 3,
                    msg: '选择角色',
                    bg: '#AE81FF',
                    time: 2
                });

                $("#role_id").focus();
                return false;
            }
            if ($("#loginname").val() == "" || $("#loginname").val() == "此用户名已存在!") {

                $("#loginname").tips({
                    side: 3,
                    msg: '输入用户名',
                    bg: '#AE81FF',
                    time: 2
                });

                $("#loginname").focus();
                $("#loginname").val('');
                $("#loginname").css("background-color", "white");
                return false;
            } else {
                $("#loginname").val(jQuery.trim($('#loginname').val()));
            }

            if ($("#NUMBER").val() == "") {

                $("#NUMBER").tips({
                    side: 3,
                    msg: '输入编号',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#NUMBER").focus();
                return false;
            } else {
                $("#NUMBER").val($.trim($("#NUMBER").val()));
            }

            if ($("#user_id").val() == "" && $("#password").val() == "") {

                $("#password").tips({
                    side: 3,
                    msg: '输入密码',
                    bg: '#AE81FF',
                    time: 2
                });

                $("#password").focus();
                return false;
            }
            if ($("#password").val() != $("#chkpwd").val()) {

                $("#chkpwd").tips({
                    side: 3,
                    msg: '两次密码不相同',
                    bg: '#AE81FF',
                    time: 3
                });

                $("#chkpwd").focus();
                return false;
            }
            if ($("#name").val() == "") {

                $("#name").tips({
                    side: 3,
                    msg: '输入姓名',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#name").focus();
                return false;
            }

            var myreg = /^(((13[0-9]{1})|159)+\d{8})$/;
            if ($("#PHONE").val() == "") {

                $("#PHONE").tips({
                    side: 3,
                    msg: '输入手机号',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#PHONE").focus();
                return false;
            } else if ($("#PHONE").val().length != 11 && !myreg.test($("#PHONE").val())) {
                $("#PHONE").tips({
                    side: 3,
                    msg: '手机号格式不正确',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#PHONE").focus();
                return false;
            }

            if ($("#EMAIL").val() == "") {

                $("#EMAIL").tips({
                    side: 3,
                    msg: '输入邮箱',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#EMAIL").focus();
                return false;
            } else if (!ismail($("#EMAIL").val())) {
                $("#EMAIL").tips({
                    side: 3,
                    msg: '邮箱格式不正确',
                    bg: '#AE81FF',
                    time: 3
                });
                $("#EMAIL").focus();
                return false;
            }

            if ($("#user_id").val() == "") {
                hasU();
            } else {
                $("#userForm").submit();
                $("#zhongxin").hide();
                $("#zhongxin2").show();
            }
        }

        //判断编码是否存在
        function hasN(USERNAME) {
            var NUMBER = $.trim($("#NUMBER").val());
            $.ajax({
                type: "POST",
                url: '<%=basePath%>user/hasN.do',
                data: {NUMBER: NUMBER, USERNAME: USERNAME, tm: new Date().getTime()},
                dataType: 'json',
                cache: false,
                success: function (data) {
                    if ("success" != data.result) {
                        $("#NUMBER").tips({
                            side: 3,
                            msg: '编号已存在',
                            bg: '#AE81FF',
                            time: 3
                        });
                        setTimeout("$('#NUMBER').val('')", 2000);
                    }
                }
            });
        }

    </script>
</head>
<body>
<form action="user/${msg}.do" name="userForm" id="userForm" method="post">
    <div id="zhongxin">
        <table>
            <tr>
                <td><input type="text" name="appId" id="appId" value="${app.appId }" maxlength="32"
                           placeholder="这里输入平台ID" title="平台ID"/></td>
            </tr>
            <tr>
                <td><input type="text" name="appName" id="appName" value="${app.appName }" maxlength="32"
                           placeholder="这里输入平台名称" title="平台名称"/></td>
            </tr>
            <tr>
                <td><input type="text" name="serverIp" id="serverIp" value="${app.serverIp }" maxlength="32"
                           placeholder="这里输入serverIp" title="serverIp"/></td>
            </tr>
            <tr>
                <td><input type="text" name="serverPort" id="serverPort" value="${app.serverPort }" maxlength="32"
                           placeholder="这里输入serverPort"
                           title="serverPort"/></td>
            </tr>
            <tr>
                <td><input type="number" name="serverClientId" id="serverClientId" value="${app.serverClientId }"
                           maxlength="32"
                           placeholder="这里输入serverClientId" title="serverClientId"/></td>
            </tr>
            <tr>
                <td><input type="email" name="serverPassword" id="serverPassword" value="${app.serverPassword }"
                           maxlength="32"
                           placeholder="这里输入serverPassword" title="serverPassword"/></td>
            </tr>
            <tr>
                <td><input type="text" name="clientSrcId" id="clientSrcId" value="${app.clientSrcId }"
                           placeholder="这里输入clientSrcId" maxlength="64"
                           title="clientSrcId"/></td>
            </tr>
            <tr>
                <td><input type="text" name="clientSecret" id="clientSecret" value="${app.clientSecret }"
                           placeholder="这里输入clientSecret" maxlength="64"
                           title="clientSecret"/></td>
            </tr>
            <tr>
                <td><input type="text" name="clientServiceId" id="clientServiceId" value="${app.clientServiceId }"
                           placeholder="这里输入clientServiceId" maxlength="64"
                           title="clientServiceId"/></td>
            </tr>
            <tr>
                <td><input type="text" name="cmebAppId" id="cmebAppId" value="${app.cmebAppId }"
                           placeholder="这里输入cmebAppId" maxlength="64"
                           title="cmebAppId"/></td>
            </tr>
            <tr>
                <td><input type="text" name="cmebPasswd" id="cmebPasswd" value="${app.cmebPasswd }"
                           placeholder="这里输入cmebPasswd" maxlength="64"
                           title="cmebPasswd"/></td>
            </tr>
            <tr>
                <td><input type="text" name="cmebIp" id="cmebIp" value="${app.cmebIp }"
                           placeholder="这里输入cmebIp" maxlength="64"
                           title="cmebIp"/></td>
            </tr>
            <tr>
                <td><input type="text" name="cmebPort" id="cmebPort" value="${app.cmebPort }"
                           placeholder="这里输入cmebPort" maxlength="64"
                           title="cmebPort"/></td>
            </tr>
            <tr>
                <td><input type="text" name="cmebVersion" id="cmebVersion" value="${app.cmebVersion }"
                           placeholder="这里输入cmebVersion" maxlength="64"
                           title="cmebVersion"/></td>
            </tr>
            <tr>
                <td><input type="text" name="registryAddress" id="registryAddress" value="${app.registryAddress }"
                           placeholder="这里输入registryAddress" maxlength="64"
                           title="registryAddress"/></td>
            </tr>
            <tr>
                <td><input type="text" name="dubboProtocol" id="dubboProtocol" value="${app.dubboProtocol }"
                           placeholder="这里输入dubboProtocol" maxlength="64"
                           title="dubboProtocol"/></td>
            </tr>
            <tr>
                <td><input type="text" name="dubboPort" id="dubboPort" value="${app.dubboPort }"
                           placeholder="这里输入dubboPort" maxlength="64"
                           title="dubboPort"/></td>
            </tr>
            <tr>
                <td><input type="text" name="serviceVersion" id="serviceVersion" value="${app.serviceVersion }"
                           placeholder="这里输入serviceVersion" maxlength="64"
                           title="serviceVersion"/></td>
            </tr>
            <tr>
                <td style="text-align: center;">
                    <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                    <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                </td>
            </tr>
        </table>
    </div>

    <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
            src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>

</form>

<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>
<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->

<script type="text/javascript">

    $(function () {

        //单选框
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});

        //日期框
        $('.date-picker').datepicker();

    });

</script>

</body>
</html>